package android_fields;

import static android_board.GUIBoard.FIELDHEIGHT;
import static android_board.GUIBoard.FIELDWIDTH;

import common.GUIColor;

import dk.dtu.compute.course02312.matadorfinal.MainActivity;
import dk.dtu.compute.course02312.matadorfinal.R;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android_board.GUIBoard;
import android_board.GUICenter;

public final class GUIJail extends AndroidField {
	private static final float IMAGEHEIGHTPART = 0.79f;
//	private static final float TITLEHEIGHTPART = 0.00f;
//	private static final float SUBTEXTHEIGHTPART = 0.19f;
	
	private ImageView iconView;

	public static class Builder extends AndroidField.Builder<GUIJail.Builder> implements
			iBuilder {
		private int pictureId = R.drawable.field_jail;

		public Builder() {
			this.bgColor = new GUIColor(125, 125, 125);
			this.description = "You are jailed";
		}

		@Override
		@SuppressWarnings("synthetic-access")
		public GUIJail build() {
			return new GUIJail(this.pictureId, "", this.subText,
					this.description, this.bgColor, this.fgColor);
		}

		public Builder setPictureId(int pictureId) {
			this.pictureId = pictureId;
			return this;
		}

		public Builder setSubText(String subText) {
			this.subText = subText;
			return this;
		}

		public Builder setDescription(String description) {
			this.description = description;
			return this;
		}
	}

	private GUIJail(int pictureId, String title, String subText,
			String description, GUIColor bgColor, GUIColor fgColor) {
		super(bgColor, fgColor, title, subText, description);

		Bitmap image = BitmapFactory.decodeResource(
				MainActivity.context.getResources(), pictureId);
		this.iconView = new ImageView(MainActivity.context);
		this.iconView.setId(GUIBoard.generateViewId());
		this.iconView.setImageBitmap(image);
		this.iconView.setPadding(2, 2, 2, 0);
		int height = (int) (IMAGEHEIGHTPART * FIELDHEIGHT);
		RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(
				FIELDWIDTH, height);
		this.subTextView.setText(this.subText);
		this.cell.addView(this.iconView, iconParams);
	}

	public String getBottomText() {
		return this.subText;
	}

	@Override
	public void displayOnCenter() {
		super.displayOnCenter();
		GUICenter.textViews[1].setCompoundDrawables(null, null, null, this.iconView.getDrawable());
		GUICenter.textViews[1].setVisibility(View.VISIBLE);
		GUICenter.textViews[3].setText(this.description);
        GUICenter.textViews[3].setVisibility(View.VISIBLE);
		super.displayCarOnCenter();
	}
}